
var zwblsjChart;
var returnZwblsjData = [];

var zwblsjObj = new Vue({
	el: '#zwblsjTab',
	data: {
		year: '',
		isAll: false,
		zsList:{
			xzspl: true,
			thlzs: true,
			cylzs: true,
			cblzs: true,
			wflzs: true,
			aqgllzs: true,
		}
	},
	created: function(){


	},
	watch:{
		"zsList.xzspl":function(val, oldVal){	//船舶登记 行政审批量
    		zwblsjChart.setOption(subStrOptionZwblsj(returnZwblsjData),true);
		},
		"zsList.thlzs":function(val, oldVal){	//改成通航类证书
    		zwblsjChart.setOption(subStrOptionZwblsj(returnZwblsjData),true);
		},
		"zsList.cylzs":function(val, oldVal){	//船员适任证书发放
    		zwblsjChart.setOption(subStrOptionZwblsj(returnZwblsjData),true);
		},
		"zsList.cblzs":function(val, oldVal){	//船舶类证书
    		zwblsjChart.setOption(subStrOptionZwblsj(returnZwblsjData),true);
		},
		"zsList.wflzs":function(val, oldVal){	//危防类证书
    		zwblsjChart.setOption(subStrOptionZwblsj(returnZwblsjData),true);
		},
		"zsList.aqgllzs":function(val, oldVal){	//安全管理类证书
    		zwblsjChart.setOption(subStrOptionZwblsj(returnZwblsjData),true);
		}
	},
	methods:{
		checkAll: function(){
			this.zsList.xzspl = this.isAll;
			this.zsList.thlzs　= this.isAll;
			this.zsList.cylzs　= this.isAll;
			this.zsList.cblzs　= this.isAll;
			this.zsList.wflzs　= this.isAll;
			this.zsList.aqgllzs　= this.isAll;
    		zwblsjChart.setOption(subStrOptionZwblsj(returnZwblsjData),true)
		}
	}
})


function bindZwblsjData(){
	if(returnZwblsjData.length == 0){
		
		$.ajax({ 
			type: "POST",
			url: "/tszt/findsjfb.jspx", 
			data: {channelIds: 370, year: zwblsjObj.year, orderBy: 36},
			success: function(data){
				if(data.code == 200){
					if(data.body.length == 0){
						zwblsjObj.year = new Date().getFullYear() - 1;
						bindZwblsjData();
					}
					returnZwblsjData = data.body;
				}
				
				bindZwblsj(returnZwblsjData);
	      	}
		});
	}
}

function subStrLegendZwblsj(){
	var legend = [];

	if(zwblsjObj.zsList.xzspl)
		legend.push('行政审批量');
    if(zwblsjObj.zsList.thlzs)
		legend.push('通航类证书');
    if(zwblsjObj.zsList.cylzs)
		legend.push('船员类证书');
	if(zwblsjObj.zsList.cblzs)
		legend.push('船舶类证书');
	if(zwblsjObj.zsList.wflzs)
		legend.push('危防类证书');
	if(zwblsjObj.zsList.aqgllzs)
		legend.push('安全管理类证书');
	return legend;
}

function subStrXAxisZwblsj(returnZwblsjData){
	var xAxis = [];
	
	returnZwblsjData.forEach(function(month){ 
		xAxis.push(month.attr_month + '月份');
	}); 
	
	return xAxis;
}


function subStrSeriesZwblsj(returnZwblsjData){
	var series = [];

	var xzsplData = [];

	var thlzsData = [];

	var cylzsData = [];

	var cblzsData = [];
	
	var wflzsData = [];
	
	var aqgllzsData = [];

	returnZwblsjData.forEach(function(val){ 
		//船舶登记改成行政审批量
		xzsplData.push(val.attr_xzspl); //总数
		//通航类证书
		thlzsData.push(val.attr_thlzs); //总数
		//船舶类证书
		cblzsData.push(val.attr_cblzs); //总数
		//船员类证书
		cylzsData.push(val.attr_cylzs); //总数
		//危防类证书
		wflzsData.push(val.attr_wflzs); //总数
		//安全管理类证书
		aqgllzsData.push(val.attr_aqgllzs); //总数
	}); 
	

	if(zwblsjObj.zsList.xzspl){	//船舶登记 行政审批数量
	    var d = 
		{
            name: '行政审批量',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#5bc0de",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: xzsplData
        };
	    series.push(d);
	}


	if(zwblsjObj.zsList.thlzs){	//改成通航类证书
	    var d = 
		{
            name: '通航类证书',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#5cb85c",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: thlzsData
        };
	    series.push(d);
	}
	
	if(zwblsjObj.zsList.cblzs){	//船舶类证书
	    var d = 
		{
            name: '船舶类证书',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#0078c1",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: cblzsData
        };
	    series.push(d);
	}

	if(zwblsjObj.zsList.cylzs){	//船员适任证书发放
	    var d = 
		{
            name: '船员类证书',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#99ccff",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: cylzsData
        };
	    series.push(d);
	}
	
	if(zwblsjObj.zsList.wflzs){	//危防类证书
	    var d = 
		{
            name: '危防类证书',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#994747",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: wflzsData
        };
	    series.push(d);
	}
	
	if(zwblsjObj.zsList.aqgllzs){	//安全管理类证书
	    var d = 
		{
            name: '安全管理类证书',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#020fb3",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: aqgllzsData
        };
	    series.push(d);
	}
	
	return series;
}

function subStrOptionZwblsj(){

	var legendData = subStrLegendZwblsj();
	var xAxisData = subStrXAxisZwblsj(returnZwblsjData);
	var seriesData = subStrSeriesZwblsj(returnZwblsjData);

    var option = {
    		toolbox: {
  			　　show: true,
  			   right: 20,     			  
  			　　feature: {
  			　　　　saveAsImage: {
  			　　　　show:true,
  			　　　　excludeComponents :['toolbox'],
  			　　　　pixelRatio: 2,
  			  itemStyle: {
  	                color: '#254065'
  	            }
  			　　　　}
  			　　}
  			},
    		title: {
    			text: zwblsjObj.year + '年'
    		},	
    		
    		 tooltip: {
               	trigger: 'axis',
               	 axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                       type: 'line'        //指示器类型。
                   },
                   formatter: function (params) {//提示框自定义
                       return formatterTip(params);
                   },
                  
      		 },

            legend: {
                data: legendData,
                textStyle: {
                    color: '#A7A7A7',
                },
            },
          
            xAxis: {
                data: xAxisData
            },
            
            yAxis: {
            	show: true
            },
        
           series: seriesData
		};
    
    
    return option;
}


function bindZwblsj(returnZwblsjData){

	zwblsjChart = echarts.init(document.getElementById('chartZwblsj'));

    var option = subStrOptionZwblsj(returnZwblsjData);
	
    // 使用刚指定的配置项和数据显示图表。
    zwblsjChart.setOption(option);
}